<template>
  <div class="wrap">
    <div class="header">
      <div class="left">
        <img :src="info.avatar" :onerror="defaultImg" class="headerUrl" alt />
        <div class="center">
          <div>
            <p>{{info.username}}</p>
            <span>订单数：{{info.total}}</span>
          </div>
          <p>{{info.signature}}</p>
        </div>
      </div>
      <div class="func">
        <p>商家</p>
      </div>
    </div>
    <div class="centers" v-if="orderList.length">
      <div class="item" v-for="item in orderList" :key="item.order_id">
        <div class="item-left">
          <img
            :src="item.order_image"
            @click="showMaxImg($event)"
            :onerror="defaultImg2"
            class="avi"
            alt
          />
          <div class="productInfo">
            <p>规格：{{item.order_size}}</p>
            <p>价格：￥{{item.customer_price }}</p>
            <p>
              商家备注：
              <span style="color:#FF536B;">{{item.remark?item.remark:'无备注'}}</span>
            </p>
          </div>
        </div>
        <div class="item-right">
          <div class="state">
            <p
              :style="item.send_state==0?'':'color:green'"
            >{{info&&info.is_get==1?item.send_state==0?'未到货':'已到货':''}}</p>
            <p @click="a_send(item)">代发</p>
          </div>
          <img
            :src=" item.select ?require('../assets/select.png'):require('../assets/radio.png')"
            class="radio"
            alt
            @click="select(item)"
          />
        </div>
      </div>
    </div>
    <div class="footer">
      <div>
        <p class="btn" @click="next">批量代发</p>
        <p class="orderNum">
          已选择个
          <span style="color:#3FD9C9;">{{num}}</span>
          订单
        </p>
      </div>
      <div @click="allSelect">
        <p>全选</p>
        <img
          :src="num===orderList.length?require('../assets/select.png'):require('../assets/radio.png')"
          class="all"
          alt
        />
      </div>
    </div>
    <van-popup v-model="show">
      <img :src="showMaxSrc" class="maxImg" :onerror="defaultImg" alt srcset />
    </van-popup>
  </div>
</template>
<style lang="scss" scoped>
.maxImg {
  width: 100%;
}
.wrap {
  background: #f7f7f7;
  width: 100%;
  height: 100vh;
}

.header {
  height: 2.186667rem;
  padding: 0 0.4rem 0.4rem;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .left {
    display: flex;
    align-items: center;
  }
  .headerUrl {
    width: 1.466667rem;
    height: 1.466667rem;
    border-radius: 50%;
    display: block;
    margin-top: 0.373333rem;
  }
  .center {
    margin-left: 0.4rem;
    div {
      // display: flex;
      // align-items: flex-end;
      margin-top: 15px;
      p {
        color: #555;
        font-size: 0.48rem;
      }
      span {
        color: #999;
        font-size: 0.293333rem;
        text-align: left;
        display: block;
        margin: 5px 0;
      }
    }
    p {
      color: #555;
      font-size: 0.266667rem;
      text-align: left;
    }
  }
  .func {
    margin-top: 15px;
    p:nth-of-type(1) {
      width: 2.24rem;
      height: 0.6rem;
      color: #999;
      border-radius: 0.4rem;
      font-size: 0.4rem;
      text-align: center;
      line-height: 0.6rem;
      margin-bottom: 0.266667rem;
    }
    p:nth-of-type(2) {
      width: 2.24rem;
      height: 0.6rem;
      background: rgba(63, 217, 201, 1);
      color: #fff;
      border-radius: 0.4rem;
      font-size: 0.373333rem;
      text-align: center;
      line-height: 0.6rem;
    }
  }
}
.centers {
  position: absolute;
  top: 2.586667rem;
  bottom: 1.2rem;
  left: 0;
  right: 0;
  overflow-y: scroll;
  .item {
    width: 9.466667rem;
    height: 2.333333rem;
    border-radius: 0.266667rem;
    background: #fff;
    margin: 0.186667rem auto 0;
    overflow: hidden;
    display: flex;
    justify-content: space-between;
    .item-left {
      display: flex;
      align-items: center;
    }
    .avi {
      width: 2rem;
      height: 2rem;
      border-radius: 0.266667rem;
      margin: 0 0.306667rem 0 0.133333rem;
      display: block;
      object-fit: cover;
    }
    .productInfo {
      display: flex;
      justify-content: space-between;
      flex-direction: column;
      height: 1.8rem;
      p {
        color: #555;
        font-size: 0.32rem;
        text-align: left;
      }
      p:nth-of-type(2) {
        margin-top: 0.133333rem;
        margin-bottom: 0.186667rem;
      }
    }
    .item-right {
      display: flex;
      .state {
        width: 2.4rem;
        height: 1.8rem;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        p:nth-of-type(1) {
          color: #ff536b;
          font-size: 0.426667rem;
          text-align: center;
          margin-top: 0.266667rem;
          margin-bottom: 0.56rem;
        }
        p:nth-of-type(2) {
          width: 2.213333rem;
          height: 0.573333rem;
          border-radius: 0.266667rem;
          text-align: center;
          background: #3fd9c9;
          font-size: 0.373333rem;
          line-height: 0.573333rem;
          color: #fff;
        }
      }
      .radio {
        width: 0.453333rem;
        height: 0.453333rem;
        border-radius: 50%;
        display: block;
        margin-right: 0.266667rem;
        margin-top: 0.3rem;
      }
    }
  }
}
.footer {
  background: #fff;
  position: fixed;
  bottom: 0;
  height: 1.2rem;
  width: 100%;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  div {
    display: flex;
    align-items: center;
  }
  .btn {
    background: #3fd9c9;
    color: #fff;
    width: 2.72rem;
    height: 0.8rem;
    border-radius: 0.373333rem;
    font-size: 0.493333rem;
    margin-left: 0.733333rem;
    margin-right: 0.266667rem;
    line-height: 0.8rem;
  }
  .all {
    width: 0.453333rem;
    height: 0.453333rem;
    border-radius: 50%;
    display: block;
    margin-right: 0.533333rem;
    margin-left: 0.533333rem;
  }
}
</style>
<script>
import { getTakeOrderList, followDele, getById } from "@/utils/interface";
import { Toast, Dialog } from "vant";
export default {
  data() {
    return {
      defaultImg: 'this.src="' + require("../assets/user2.png") + '"',
      defaultImg2: 'this.src="' + require("../assets/timg.jpg") + '"',
      orderList: [],
      num: 0,
      allSelectState: false,
      inof: {},
      show: false,
      showMaxSrc: "",
      userInfo: {},
      sendStateValue: ""
    };
  },
  created() {
    document.title = "取货订单";
    this.sendStateValue = this.$route.query.state;
    this.info = JSON.parse(this.$route.query.info);
    this.getList(this.$route.query.shopId,this.sendStateValue,this.$route.query.date);

    this.getUserInfo();
    console.log(this.$route.query);
  },
  methods: {
    next() {
      // if(!this.info.is_instead){
      //   Toast.fail('该商家暂不提供该服务')
      //   return false
      // }
      Toast.fail("此功能即将上线");
      return false;
      let orderData = [];
      this.orderList.map(item => {
        if (item.select) {
          orderData.push({ img: item.order_image, id: item.order_id });
        }
      });
      if (orderData.length == 0) {
        return false;
      }
      this.$router.push({
        path: "submitOrder",
        query: {
          orderList: JSON.stringify(orderData),
          name: this.info.username
        }
      });
    },

    a_send(item) {
      // if (!this.info.is_instead) {
      //   Toast.fail("该商家暂不提供该服务");
      //   return false;
      // }
      Toast.fail("此功能即将上线");
      return false;
      let orderData = [{ img: item.order_image, id: item.order_id }];
      this.$router.push({
        path: "submitOrder",
        query: {
          orderList: JSON.stringify(orderData),
          name: this.info.username
        }
      });
    },
    getList(parentId,state,createDate) {
      getTakeOrderList({ parentId ,sendState:state.toString(),createDate}).then(res => {
        res.data.data.map(item => {
          item.select = false;
        });
        this.orderList = res.data.data;
      });
    },
    select(item) {
      item.select = !item.select;
      this.num = 0;
      this.orderList.map(item => {
        if (item.select) {
          this.num++;
        }
      });
    },
    allSelect() {
      this.allSelectState = !this.allSelectState;
      if (this.allSelectState) {
        this.orderList.map(item => {
          item.select = true;
        });
        this.num = this.orderList.length;
      } else {
        this.orderList.map(item => {
          item.select = false;
        });
        this.num = 0;
      }
    },

    showMaxImg(e) {
      console.log(e.srcElement.src);
      this.show = true;
      this.showMaxSrc = e.srcElement.src;
    },
    getUserInfo() {
      getById().then(res => {
        if (res.data.code == 200) {
          this.userInfo = res.data.data;
        }
      });
    }
  }
};
</script>